<?php
/**
 * Created by PhpStorm.
 * User: 程序猴
 * Date: 2018/4/20
 *  Q Q: 505413
 * Time: 12:01
 */

namespace app\admin\controller;
use app\admin\controller\Base;
use payment\alipay;
use think\Db;
class Payment extends Base
{
    //企业支付宝支付
    public function qAlipay()
    {
        if(request()->isAjax()){
            $param = input('post.');
            if(!empty($param['status'])){
                if($param['status'] == 'on') {
                    $params['status'] = '1';
                }
            }else{
                $params['status'] = '0';
            }
            $params['config_value'] = json_encode($param);//序列化

            $data = Db::name('plugin')->where(array('Code'=>'qalipay'))->update($params);
            if(false === $data)
            {
                return json(['code' => -1, 'msg' => '保存失败，请稍后再试']);
            }else{
                return json(['code' => 1, 'msg' => '保存成功']);
            }
        }
        $info = Db::name('plugin')->where(array('Code'=>'qalipay'))->find();
        $status = Db::name('plugin')->where(array('Code'=>'qalipay'))->find();
        $info = json_decode($info['config_value'],true);//反序列化

        $this->assign('status',$status);
        $this->assign('info',$info);
        return $this->fetch();
    }
    //企业微信支付
    public function qWxpay()
    {
        if(request()->isAjax()){
            $param = input('post.');
            if(!empty($param['status'])){
                if($param['status'] == 'on') {
                    $params['status'] = '1';
                }
            }else{
                $params['status'] = '0';
            }
            $params['config_value'] = json_encode($param);//序列化
            $data = Db::name('plugin')->where(array('Code'=>'qwxpay'))->update($params);
            if(false === $data)
            {
                return json(['code' => -1, 'msg' => '保存失败，请稍后再试']);
            }else{
                return json(['code' => 1, 'msg' => '保存成功']);
            }
        }
        $info = Db::name('plugin')->where(array('Code'=>'qwxpay'))->find();
        $status = Db::name('plugin')->where(array('Code'=>'qwxpay'))->find();
        $info = json_decode($info['config_value'],true);//反序列化

        $this->assign('status',$status);
        $this->assign('info',$info);
        return $this->fetch();
    }
    //招商支付
    public function zspay(){
        if(request()->isAjax()){
            $param = input('post.');
            if(!empty($param['status'])){
                if($param['status'] == 'on') {
                    $params['status'] = '1';
                }
            }else{
                $params['status'] = '0';
            }
            $params['config_value'] = json_encode($param);//序列化
            $data = Db::name('plugin')->where(array('Code'=>'zspay'))->update($params);
            if(false === $data)
            {
                return json(['code' => -1, 'msg' => '保存失败，请稍后再试']);
            }else{
                return json(['code' => 1, 'msg' => '保存成功']);
            }
        }
        $info = Db::name('plugin')->where(array('Code'=>'zspay'))->find();
        $status = Db::name('plugin')->where(array('Code'=>'zspay'))->find();
        $info = json_decode($info['config_value'],true);//反序列化

        $this->assign('status',$status);
        $this->assign('info',$info);
        return $this->fetch();
    }
    //个人支付宝支付
    public function gAlipay()
    {
        return $this->fetch();
    }
    //个人微信支付
    public function gWxpay()
    {
        return $this->fetch();
    }
    /************************************第三方登录******************************************/
    //QQ登录
    public function qqLogin()
    {
        if(request()->isAjax()){
            $param = input('post.');
            if(!empty($param['status'])){
                if($param['status'] == 'on') {
                    $params['status'] = '1';
                }
            }else{
                $params['status'] = '0';
            }
            $params['config_value'] = json_encode($param);//序列化
            $data = Db::name('plugin')->where(array('Code'=>'qq_login'))->update($params);
            if(false === $data)
            {
                return json(['code' => -1, 'msg' => '保存失败，请稍后再试']);
            }else{
                return json(['code' => 1, 'msg' => '保存成功']);
            }
        }
        $info = Db::name('plugin')->where(array('Code'=>'qq_login'))->find();
        $status = Db::name('plugin')->where(array('Code'=>'qq_login'))->find();
        $info = json_decode($info['config_value'],true);//反序列化

        $this->assign('status',$status);
        $this->assign('info',$info);
        return $this->fetch();
    }
    //新浪微博登录
    public function wbLogin()
    {
        if(request()->isAjax()){
            $param = input('post.');
            if(!empty($param['status'])){
                if($param['status'] == 'on') {
                    $params['status'] = '1';
                }
            }else{
                $params['status'] = '0';
            }
            $params['config_value'] = json_encode($param);//序列化
            $data = Db::name('plugin')->where(array('Code'=>'wb_login'))->update($params);
            if(false === $data)
            {
                return json(['code' => -1, 'msg' => '保存失败，请稍后再试']);
            }else{
                return json(['code' => 1, 'msg' => '保存成功']);
            }
        }
        $info = Db::name('plugin')->where(array('Code'=>'wb_login'))->find();
        $status = Db::name('plugin')->where(array('Code'=>'wb_login'))->find();
        $info = json_decode($info['config_value'],true);//反序列化

        $this->assign('status',$status);
        $this->assign('info',$info);
        return $this->fetch();
    }
    /************************************短信配置******************************************/
    //阿里短信
    public function aliSms()
    {
        if(request()->isAjax()){
            $param = input('post.');
            if(!empty($param['status'])){
                if($param['status'] == 'on') {
                    $params['status'] = '1';
                }
            }else{
                $params['status'] = '0';
            }
            $params['config_value'] = json_encode($param);//序列化
            $data = Db::name('plugin')->where(array('Code'=>'aliSms'))->update($params);
            if(false === $data)
            {
                return json(['code' => -1, 'msg' => '保存失败，请稍后再试']);
            }else{
                return json(['code' => 1, 'msg' => '保存成功']);
            }
        }
        $info = Db::name('plugin')->where(array('Code'=>'aliSms'))->find();
        $status = Db::name('plugin')->where(array('Code'=>'aliSms'))->find();
        $info = json_decode($info['config_value'],true);//反序列化

        $this->assign('status',$status);
        $this->assign('info',$info);
        return $this->fetch();
    }
    /************************************邮件配置******************************************/
    public function mail(){
        if(request()->isAjax()){
            $param = input('post.');
            if(!empty($param['status'])){
                if($param['status'] == 'on') {
                    $params['status'] = '1';
                }
            }else{
                $params['status'] = '0';
            }
            $params['config_value'] = json_encode($param);//序列化
            $data = Db::name('plugin')->where(array('Code'=>'mail'))->update($params);
            if(false === $data)
            {
                return json(['code' => -1, 'msg' => '保存失败，请稍后再试']);
            }else{
                return json(['code' => 1, 'msg' => '保存成功']);
            }
        }
        $info = Db::name('plugin')->where(array('Code'=>'mail'))->find();
        $status = Db::name('plugin')->where(array('Code'=>'mail'))->find();
        $info = json_decode($info['config_value'],true);//反序列化

        $this->assign('status',$status);
        $this->assign('info',$info);
        return $this->fetch();
    }
}